// http://code.google.com/chrome/extensions/options.html

var options = {
	defaultTemplate: '<img src="{photo-url}"/>',
	customTemplates: [],
	load: function() {
		var t = ti.data.getObject('templates');
		if (t == undefined || t == null || typeof(t) != 'object') {
			this.reset();
		} else {
			this.customTemplates = t;
		}
	},
	save: function() {
		ti.data.set('templates', this.customTemplates);
	},
	reset: function() {
		this.customTemplates = [];
		this.customTemplates.push(new templateObject('*', this.defaultTemplate));
	},
	template: {
		add: function(url, template) {
			// check duplicates
			options.customTemplates.push(new templateObject(url, template));
		},
		remove: function(url) {
			
		},
		get: function(url) {
			if (url == null) { url = '*'; }
			for (var i in options.customTemplates) {
				if (options.customTemplates[i].url == url) {
					return options.customTemplates[i];
				}
			}
			return null;
		}
	}
}

function templateObject(url, template) {
	this.url = url;
	this.template = template;
}